#include "widget.h"
#include "ui_widget.h"
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    //先获取到这两个输入框之间的时间都是什么
    QDateTime timeold = ui->dateTimeEdit->dateTime();
    QDateTime timeNow = ui->dateTimeEdit_2->dateTime();
    //计算日期差值
    //int days = timeold.daysTo(timeNow);
    int second = timeold.secsTo(timeNow);
    //把秒数换算成小时
    int hours = (second / 3600) % 24;
    int days = (second / 3600) / 24;
    //把计算结果放到label
    ui->label->setText(QString("相隔") + QString::number(days) + QString("天") + QString::number(hours) + QString("小时"));
}
